package com.yangming.springboot.deepin.playTest;


import java.util.concurrent.atomic.AtomicReference;

/**
 * @创建人 ym
 * @创建时间 2021/4/22 0022
 * @描述
 **/
public class AtomicReferenceTest {

    public static AtomicReference<User> atomicUserRef = new AtomicReference<User>();
    public static void main(String[] args){
        User user = new User("conna", 123);
        atomicUserRef.set(user);
        User updateUser = new User("shinichi", 17);
        atomicUserRef.compareAndSet(user, updateUser);
        System.out.println(atomicUserRef.get().getName());
        System.out.println(atomicUserRef.get().getOld());
    }
    private static class User{
        private String name;
        private int old;
        public User(String name, int old){
            this.name = name;
            this.old = old;
        }
        public String getName(){
            return this.name;
        }
        public int getOld(){
            return this.old;
        }
    }

}
